package com.youkeda.test.threadpool;

/**
 * @author CoderXshuai
 */
public class Person implements Runnable {
    private String name;
    private String type;
    private Account Account;
    private static Object object = new Object();

    @Override
    public void run() {
        synchronized (object) {
            double preMoney = Account.getMoney();
            switch (name) {
                case "姚远":
                    if (Account.getMoney() > 50) {
                        Account.outMoney(50, "atm");
                        System.out.println(type + "取钱" + (preMoney - Account.getMoney()) + "元，剩余" + Account.getMoney() + "元！");
                    } else {
                        System.out.println("取款50元失败，余额" + Account.getMoney() + "元");
                    }
                    break;
                case "路晓欧":
                    if (Account.getMoney() > 100) {
                        Account.outMoney(100, "window");
                        System.out.println(type + "取钱" + (preMoney - Account.getMoney()) + "元，剩余" + Account.getMoney() + "元！");
                    } else {
                        System.out.println("取款100元失败，余额" + Account.getMoney() + "元");
                    }
                    break;
                default:
                    break;
            }
        }
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public Person(String name, Account account, String type) {
        this.name = name;
        this.Account = account;
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public com.youkeda.test.threadpool.Account getAccount() {
        return Account;
    }

    public void setAccount(com.youkeda.test.threadpool.Account account) {
        Account = account;
    }
}
